﻿/*
* McLoader.js
* Copyright 1997-2017 Medicom Inc. All rights reserved.
* Author: Medicom
* Version: 4.1.10.1
* Date: 2017-11-22
* Write by: arjun
*/
//嵌套时，请调整为美康合理用药服务器IP地址，不要最后的 “/”
this.mcWebServiceUrl ="http://172.101.107.102/PASSPharmReview";

var McLoadJSName = 'McLoader.js';
var McBaseUrl = McGetLoadBaseUrl();

this.IsMcAsyncLoadJs = false;  //是否动态加载McAsyncLoadJs

function McGetLoadBaseUrl() {

    if (!!mcWebServiceUrl) {
        return mcWebServiceUrl + '/PassContent/PassJs/';
    }

    var regex = new RegExp(McLoadJSName.replace('.', '\.'), 'gi');
    var elems = document.getElementsByTagName('SCRIPT');
    for (var i = 0; i < elems.length; i++) {
        var src = elems[i].getAttribute('src');
        if (regex.test(src)) {
            var reg = /\?v=.*?$/gi;//去掉版本号
            return src.replace(regex, '').replace(reg, '');
        }
    }
    return '';
}

//McAjax.Ready();

// dropIt
/* function McLoadJs(src) {
    document.write('<script src="' + src + '" type="text/javascript"></script>');
} */

function McLoadJs(src) {
  const script = document.createElement('script')
    script.className = 'pass-js-importer'
    script.src = src
    script.type = 'text/javascript'
    document.getElementsByTagName('body')[0].appendChild(script)
}

// dropIt
/* function McLoadCss(href) {
  document.write('<link href="' + href + '" rel="stylesheet" type="text/css" />');
} */

function McLoadCss(href) {
    const link = document.createElement('link')
    link.href = href
    link.rel = 'stylesheet'
    link.type = 'text/css'
    document.getElementsByTagName('body')[0].appendChild(link)
}

function McAsyncLoadJs(src, thenFunc) {

    var head = document.getElementsByTagName('HEAD')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = src;
    head.appendChild(script);

    script.onload = script.onreadystatechange = function () {
        var rs = this.readyState;
        if (!rs     //这是FF的判断语句，因为ff下没有readyState这人值，IE的readyState肯定有值
            || rs == 'loaded' || rs == 'complete'   // 这是IE的判断语句
        ) {
            if (thenFunc && (typeof (thenFunc)).toLowerCase() == 'function') {
                thenFunc();
            }
        }
    }
}


function McAsyncLoadCss(href) {
    var head = document.getElementsByTagName('HEAD')[0];
    var link = document.createElement("link");
    link.href = href;
    link.rel = 'stylesheet';
    head.appendChild(link);
}

McLoadConfig();

function McMakeTimeStamp() {
    return new Date().getTime();
}

function McLoadConfig() {
    if (!window.IsMCGlobalLoadJs) {
        if (typeof (IsLoadMcPass) == "undefined" || IsLoadMcPass == 1) {
            if (!IsMcAsyncLoadJs) {
                McLoadJs(McBaseUrl + 'McConfig.js?t=' + McMakeTimeStamp());
            } else {
                if (window.addEventListener) {
                    window.addEventListener("load", McAsyncLoadJs(McBaseUrl + 'McConfig.js?t=' + McMakeTimeStamp()));
                } else if (window.attachEvent) {
                    window.attachEvent("onload", McAsyncLoadJs(McBaseUrl + 'McConfig.js?t=' + McMakeTimeStamp()));
                } else {
                    window.onload = McAsyncLoadJs(McBaseUrl + 'McConfig.js?t=' + McMakeTimeStamp());
                }
            }
        }
    }
}


//兼容性处理，异步加载时 mcpassim.js 可能未及时加载
window.Params_MC_PASSIM_In = function () {
}
window.Params_MC_PASSIM_In.prototype.Init = function () {
    var the = this;
    function _load() {
        if (!!!the.hiscode) {
            window.$passim.init(the.doctor, mc_passim_url, mc_passim_position, mc_passim_width, mc_passim_height, mc_passim_offset_bottom);
        } else {
            window.$passim.init([the.hiscode, the.doctor], mc_passim_url, mc_passim_position, mc_passim_width, mc_passim_height, mc_passim_offset_bottom);
        }
    }
    var _timer = null;
    function _init() {
        if (!window.$passim) {
            if (_timer != null) {
                clearTimeout(_timer);
            }
            _timer = setTimeout(_init, 500);
            return;
        }
        _load();
    }
    _timer = setTimeout(_init, 1000);
}


//定义HIS那边可能需要用的McJsAll.js里面的对象和方法。


var McDrugsArray = new Array();
var McAllergenArray = new Array();
var McMedCondArray = new Array();
var McOperationArray = new Array();
var McLabArray = new Array();
var McExamArray = new Array();
var McRecipeArray = new Array();
var MCpatientInfo;
var MCPASSclient;
var MCModuleParam;
var MCRequestSource;

var McInputJsonInfos = new Array();

var MCrefModuleArray = new Array();
var MCscreenModuleArray = new Array();
var MCdataVersion = "";    //database version
var MCprojectVersion = ""; //core version
var MCcanGetScreenDtlRes = 0;//是否有权限获取审查简要信息json串
var MChospitalName = ""; //医院名称UserName或者区域医疗名称RHCName
var MCmhiscode = "";//医院mhiscode
var McrefTipArray = new Array(); //菜单哪些模块可用，包括自定义查询的
var McScreenReasonArray = new Array(); //审查，理由必填项
var McDoModuleRes;//Mc_DoModule接口返回的结果
var McStdHospId;//Mc_DoModule接口返回的StdHospId
var McIsPRRequest = 0;//是不是PR传过来的请求
var McCanClickDetail = 1;//pr有的页面不需要显示详细

var MC_global_CheckMode = "mz";
var MC_Is_SyncCheck = false;
/*理由*/
var Params_MC_UseReason_In = function () {
    Hiscode = "";
    Hisname = "";
    PatStatus = 1;
    InHospNo = "";
    VisitCode = "";
    PatCode = "";
    RecipNo = "";
    OrderDeptCode = "";
    OrderDoctorCode = "";
    OrderStartTime = "";
    OrderEndTime = "";
    OrderExecuteTime = "";
    DrugUniqueCode = "";
    DoseUnit = "";
    DosePerTime = "";
    Frequency = "";
    IsTempDrug = 0;
    ModuleID = 0;
    ModuleName = "";
    Slcode = 0;
    Severity = "";
    Warning = "";
    ModuleItems = "USER";
    OtherInfo = "";
    IsForStatic = 1;
    reason = "";

};

var Params_MC_ModuleParam_In = function () {
    CheckMode = MC_global_CheckMode;
    ClientIP = "";
};
MCModuleParam = new Params_MC_ModuleParam_In();

var Params_MC_PASSclient_In = function () {
    HospID = ""; //医院编码
    HospName = ""; //医院名称
    UserID = "";
    UserName = "";
    DeptID = "";
    DeptName = "";
    IP = "";
    PCName = "";
    OSInfo = ""; //操作系统
    Resolution = ""; //分辨率
    PassVersion = "1";//1pc 2pad
    mac = "";//服务器电脑mac地址
    otherinfo = "";//其它信息,备用
    CheckMode = MC_global_CheckMode;//在病人信息里取了，这里不要了；但是2016-08-22刘春梅说要留起 兼容新JS 旧Core的情况
    ProductCode = "mlf35wieQdgHJ478gk06slVGSMrhy9Y2yjfhlkTv1";
    ClientVersion = 2009;
    ReScreen = 0;
};
MCPASSclient = new Params_MC_PASSclient_In();

var Params_MC_queryDrug_In = function () {
    ReferenceCode = ""; //用于查询的编码
    CodeName = "";       //名称
    CodeSource = "USER"; //来源
    IsDrug = 1;         //1-药品 0-具体某一模块对应编码
    ReferenceType = 0;  //查询右键菜单是否可用 0，1，2，3
    DisplayMode = 1;    //显示模板 1 -cs ;2 bs调用core不返回说明书图片base64编码（没这样用）
    RefMode = 1;        //1pass 2user
    MCDEXUrl = "";
    DrugNameEncode = "";
};

var MC_global_queryDrug = new Params_MC_queryDrug_In();
var McDetailItems = new Array(); //查询的明细
var McDetailItemsScreen = new Array(); //审查的明细

//明细
var McDetailItems_In = function () {
    Delimiter = "";
    SubDelimiter = "";
    DetailParams = "";
    DetailType = 0;
    DetailTip = "";
    Abstract = "";
    LinkText = ""; //用于查更多明细的提示文本
    LinkParams = ""; //用于查更多明细的查询参数
};

var Params_MC_Patient_In = function () {
    PatCode = "";   //编号
    InHospNo = "";  //门诊号/住院号
    VisitCode = ""; //门诊号/住院次数
    Name = "";      //姓名
    Sex = "";       //性别
    Birthday = "";  //出生日期
    HeightCM = "";  //身高（cm）
    WeighKG = "";   //体重（kg）
    DeptCode = "";    //科室编码
    DeptName = "";    //科室名称
    DoctorCode = "";  //主管医生编码
    DoctorName = "";  //主管医生姓名
    PatStatus = 1;    //状态 0-出院，1-住院（默认），2-门诊，3-急诊
    IsLactation = -1; //是否哺乳 -1-无法获取哺乳状态（默认） 0-不是 1-是
    IsPregnancy = -1; //是否妊娠 -1-无法获取妊娠状态（默认） 0-不是 1-是 2
    PregStartDate = ""; //妊娠开始日期，不为空，则计算妊娠期，否则出全期数据
    HepDamageDegree = -1; //-1-无法获取肝损害状态（默认） 0-无肝损害  1-存在肝损害，但损害程度不明确 2-轻度 3-中度 4-重度
    RenDamageDegree = -1; //-1-无法获取肾损害状态（默认） 0-无肾损害  1-存在肾损害，但损害程度不明确 2-轻度 3-中度 4-重度
    UseTime = ""; //审查时间 不提供给HIS使用，如果把这个时间改到开始时间和结束时间之外，那就审查不出问题
    CheckMode = MC_global_CheckMode; //审查模式,HIS传入
    IsDoSave = 1; //是否采集
    Age = "";      //年龄
    PayClass = ""; //费别
    IsTestEtiology = 0; //是否做过病原学检查  0-未做过（默认） 1-做过
    InHospDate = "";  //入院日期
    OutHospDate = ""; //出院日期
    IDCard = "";    //身份证号
    Telephone = ""; //病人联系电话
    Urgent = 0; //是否加急 0-普通（默认） 1-加急
    MedicareType = 0; //医保类型 0-非医保病人（默认） 1-医保病人 >1-其它类型（暂未启用）
    IsFast = 0; //禁食
    Temperature = ""; //体温
    PatLevel = "";//病人身份
    medicalcharge = "";//就医方式   1-普通住院 2-生育住院 3-工伤住院 4-新生儿住院 5-普通门诊 6-特殊门诊 7-单病种住院
    hospitallevel = "";//医院级别  1-三级甲等 2-三级乙等 3-三级丙等 4-二级甲等 5-二级乙等 6-二级丙等 7-一级甲等 8-一级乙等 9-一级丙等 10-其他医院
    multidaydosepriv = "";//特殊病人超多日用量审批标记（四川省人民医院）0：未经HIS审批或审批不通过，需要PASS按正常病人审查（默认）1：HIS系统审批通过，病人的所有药品按90天审查
    bedno = "";//病人床号
    doucmentno = "";//病案号
    costtype = ""; // 费用类型【中日友好医院】V1912：BS测试程序接口变动--新增属性
    warddesc = "";//病区名称
    isdialysis = "-1";// “是否透析” 0-不是，1-是，默认：-1（未知） add by wkq for V2103
};

var Params_Mc_Drugs_In = function () {//31
    RecipNo = ""; //处方号
    Index = "";        //药品序号
    OrderNo = 1; 		//医嘱号 如果传的是-1，得给他自动++
    DrugSource = "USER";
    DrugUniqueCode = ""; //药品唯一码
    DrugName = ""; 	//药品名称
    DoseUnit = "";   	//给药单位
    Form = ""; //剂型
    Strength = ""; //规格
    CompName = ""; //厂家
    RouteSource = "USER";
    RouteCode = ""; 	//给药途径编码
    RouteName = "";  	//给药途径名称
    FreqSource = "USER";
    Frequency = ""; 	//用药频次
    DosePerTime = ""; 	//单次用量
    StartTime = ""; 	//开嘱时间
    EndTime = ""; 		//停嘱时间
    ExecuteTime = ""; 	//执行时间
    DeptCode = ""; 	//开嘱科室编码
    DeptName = ""; 	//开嘱科室名称
    DoctorCode = ""; 	//开嘱医生编码
    DoctorName = ""; 	//开嘱医生姓名
    GroupTag = ""; 	//成组标记
    IsTempDrug = 0;    //是否临时用药 0-长期 1-临时
    OrderType = 0;     //医嘱类别标记  0-在用（默认），1-已作废，2-已停嘱，3-出院带药
    Pharmacists = ""; //审核/调配药师
    Pharmacists_ = ""; //核对/发药药师
    Num = ""; //药品开出数量
    NumUnit = ""; //药品开出数量单位
    Cost = "";   //费用
    Purpose = 0; //用药目的(1可能预防，2可能治疗，3预防，4治疗，5预防+治疗, 0默认)
    OprCode = ""; //手术编号，如果对应多手术，用'，'隔开，表示该药为该编号对应的手术用药
    MediTime = ""; //用药时机 （术前、术中、术后）？（0- 未使用 1-  0.5h以内  2- 0.5-2h  3-大于2h）
    Remark = "";   // 医嘱备注
    driprate = "0";//滴速(120滴/分钟)
    driptime = "0";//滴时间(滴100分钟)
    IsOtherRecip = 0; // 历史处方标记 只在门诊生效 add by liuchunmei 2016-12-23 添加
    duration = 0; // 用药天数接口 add by liuchunmei 2017-04-25
    doseday = "";// 日剂量
    skintest = "";//皮试结果 1-阳性、0-阴性
    reciptypecode = "";//处方类型编码
    reciptypename = "";// 处方类型名称
    moredaydesc = "";// 超多日用量说明
    pharmacycode = "";//药房编码
    pharmacyname = "";//药房名称
    driprange = "";//滴速范围
    doctorpriv = "";//是否审批通
    executivedept = "";//执行科室
    dosetype = ""; //剂量类型：'0'或''：常规剂量   '1'：首次剂量   '2'：维持剂量
    firstdayfreq = ""; //首日用药频次 -1或空串或不传或不是数字：根据系统设置判断开嘱当日是否用药； 0-首日不用药； >0：首日用药次数。
    decoction = ""; //煎煮方法名称
    ischronicdisease = "-1";//慢病标记

};

var Params_Mc_Allergen_In = function () {
    Index = "";        //序号
    AllerSource = "USER";
    AllerCode = "";    //编码
    AllerName = "";    //名称
    AllerSymptom = ""; //过敏症状
};

var Params_Mc_MedCond_In = function () {
    RecipNo = ""; //处方号
    Index = "";        //诊断序号
    DisSource = "USER";
    DiseaseCode = "";  //诊断编码
    DiseaseName = "";  //诊断名称
    DisTimeType = 0; //0-出院诊断（默认） 1-入院诊断 当为门诊病人时，不计算该标记
    Ishospinfection = -1; //是否院类继发感染   1-是 0-不是
    starttime = "";//诊断开始时间
    endtime = "";  //诊断结束时间
};

var Params_Mc_Operation_In = function () {
    Index = "";        //序号
    OprCode = "";      //编码
    OprName = "";      //名称
    IncisionType = "1"; //切口类型
    OprStartDate = ""; //手术开始时间（YYYY-MM-DD HH:MM:SS)
    OprEndDate = "";   //手术结束时间 （YYYY-MM-DD HH:MM:SS)
    OprMediTime = -1; //手术用药时机   0- 未使用 1-  0.5h以内  2- 0.5-2h  3-大于2h
    OprTreatTime = -1; //手术预防使用抗菌药物疗程  单位（小时）
    OprInBloodTransfusion = -1;
    OprCombinedMediNum = -1;
    OprCombinedMediOrderCodes = "";
    OprLength = -1;


};

var Params_Mc_Lab_In = function () {
    RequestNo = "";    // 检验/检查申请单序号
    LabExamCode = "";  // 检验/检查申请项目编码
    LabExamName = "";  // 检验/检查申请项目名称
    StartDateTime = "";// 检验/检查申请单下达时间
    DeptCode = "";     // 申请科室
    DeptName = "";     // 申请科室名称
    DoctorCode = "";   // 申请医生编码
    DoctorName = "";   // 申请医生
};

var Params_Mc_Exam_In = function () {
    RequestNo = "";    // 检验/检查申请单序号
    LabExamCode = "";  // 检验/检查申请项目编码
    LabExamName = "";  // 检验/检查申请项目名称
    StartDateTime = "";// 检验/检查申请单下达时间
    DeptCode = "";     // 申请科室
    DeptName = "";     // 申请科室名称
    DoctorCode = "";   // 申请医生编码
    DoctorName = "";   // 申请医生
};

var Params_Mc_Recipe_In = function () {
    RecipeNo = "";//处方号
    RecipeTypeCode = "";//处方类型编码
    RecipeTypeName = "";//处方类型名称  1-普通、2-儿科、3-急诊、4-麻醉、5-精一、6-精二、7-中药
    RecipeRouteCode;//处方给药途径编码
    RecipeRouteName;//处方给药途径名称
    RecipeFreq;//处方频次
    RecipeDosage;//处方剂数
    RecipeMark;//处方备注
    ischronicdisease = "-1";//处方慢性病标记（1-慢性病 0-非慢性病 -1-未知） add by wkq 2019.09.17 for v1912
    ChmNDayPereach = 1; // 每剂使用天数，空串或不传或不是>0的数字：1；>0：每剂实际使用天数 add by wkq 2020.01.21 for v2003
    cost = "";//处方金额
    starttime = "";//增加“处方时间”要素 add by wkq 2020.12.16 for V2103
};

var McDetailItemsScreen = new Array(); //审查的明细
//审查的明细
var McDetailItems_In = function () {
    Delimiter = "";
    SubDelimiter = "";
    DetailParams = "";
    DetailType = 0;
    DetailTip = "";
    Abstract = "";
    LinkText = "";   //用于查更多明细的提示文本
    LinkParams = ""; //用于查更多明细的查询参数
};

/*获取PR中处方状态*/
var Params_MC_GetStatus_In = function () {
this.HospID =     "";   //医院编码
this.PatCode =     "";  //病人编号
this.InHospNo =     ""; //门诊号/住院号
this.VisitCode =     "";//门诊号/住院次数
this.RecipNo =     "";  //处方号
this.TaskType =     2; //门诊2，住院1
};
var McGetStatus = new Params_MC_GetStatus_In();



//用药自查
var McPASS = {};
McPASS.OpenRefPlatform = function (type) {

}

function MDC_PR_GetStatusSync() {
    return 1;
}

function MDC_PR_GetStatus(callback) {
    return 1;
}

function MDC_getWarningCode(drugindex) {
    return 0;
}

function MDC_DoCheck(_callback, _isShowWindow) {
    if (typeof _callback == "function") {
        _callback(0);
    }
}
function MDC_DoScreenByJson(_json, _callback, _isShowWindow, width, height) {
    if (typeof _callback == "function") {
        _callback(0);
    }
}

function MDC_DelRecipeInfo(pcPatCode, pcInHospNo, pcVisitCode, pcRecipeNo, piTaskType, callback) {
    if (typeof callback == "function") {
        callback(1);
    }
}

function MDC_ShowWarningHint(pcIndex, notDoctor, event, func) {
    if (typeof func == "function") {
        func();
    }
}

function MDC_GetPGURL(callback) {

}

function MDC_DoRefDrug(ptype) {

}
function MDC_GetResultDetail(pcIndex) {

}

function MDC_DoPassCommand(_cmdtype, _callback) {

}


function Mc_getCurrentTime() {
    var date = new Date();//当前时间
    var year = date.getFullYear() //返回指定日期的年份
    var month = Mc_repair(date.getMonth() + 1);//月
    var day = Mc_repair(date.getDate());//日
    var hour = Mc_repair(date.getHours());//时
    var minute = Mc_repair(date.getMinutes());//分
    var second = Mc_repair(date.getSeconds());//秒

    //当前时间
    var curTime = year + "-" + month + "-" + day
        + " " + hour + ":" + minute + ":" + second;
    return curTime;
}

//补0
function Mc_repair(i) {
    if (i >= 0 && i <= 9) {
        return "0" + i;
    } else {
        return i;
    }
}

function MDC_GetSysPrStatus(StatusNo, showdetail) {
    if (showdetail && (showdetail == "detail" || showdetail == "1")) {
        return { "Status": 1, "StatusDesc": "异常通过，审查未获取到PR状态对象。", "WorkerId": "审方中心", "AuditTime": Mc_getCurrentTime() };
    } else {
    return 1;
    }
}

var mc_product_switch = {
    PASS: 1,
    PR: 1
};
